package com.wwz.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;


/**
 * <p>Description:全部流程实例挂起与激活</p >
 * 表：
 *
 * <p>Copyright: Copyright (c)2021</p >
 * <P>Created Date :2021-04-07</P>
 * <P>@version 1.0</P>
 */
public class SuspendProcessInstance2 {
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        //2.得到repositoryService
        RuntimeService runtimeService = processEngine.getRuntimeService();

        //3.查询流程实例
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                .processInstanceId("22501").singleResult();


        //4.得到当前流程定义实例是否 挂起
        boolean suspended = processInstance.isSuspended();

        String processInstanceId = processInstance.getId();

        //5.判断
        if(suspended){
            //是暂停 激活操作
            runtimeService.activateProcessInstanceById(processInstanceId);
            System.out.println("流程定义："+processInstanceId+"被激活");
        }else {
            runtimeService.suspendProcessInstanceById(processInstanceId);
            System.out.println("流程定义："+processInstanceId+"被挂起");
        }

    }
}
